#!/usr/bin/python
# -*- coding: utf-8 -*-

#-------------------------------------------------
#Create At: 2008-5-30 上午02:35:49 
#Create By: Fla.sam
#
#DESC: build SNote execute programe
#
#-------------------------------------------------

from distutils.core import setup
import cPickle as pickle
import py2exe
import sys
import os
import time

counter_start = 100
intro = 'SNote Main'
try:
    f = open( 'build_counter', 'r' )
except IOError:
    f = open( 'build_counter', 'w' )
    pickle.dump( counter_start, f )
    f.close()
    
counter = int( pickle.load( f ) ) + 1
f.close()

f = open( 'build_counter', 'w' )
pickle.dump( counter, f )
f.close()


# ModuleFinder can't handle runtime changes to __path__, but win32com uses them

try:
    import modulefinder
    import win32com
    for p in win32com.__path__[1:]: # do not edit it
        modulefinder.AddPackagePath( "win32com", p )
    for extra in ["win32com.shell"]: #,"win32com.mapi"
        __import__( extra )
        m = sys.modules[extra]
        for p in m.__path__[1:]:
            modulefinder.AddPackagePath( extra, p )
except ImportError:
    # no build path setup, no worries.
    pass
  
################################################################
# A program using wxPython

# The manifest will be inserted as resource into test_wx.exe.  This
# gives the controls the Windows XP appearance (if run on XP ;-)
#
# Another option would be to store it in a file named
# test_wx.exe.manifest, and copy it with the data_files option into
# the dist-dir.
#
manifest_template = '''
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">
<assemblyIdentity
    version="5.0.0.0"
    processorArchitecture="x86"
    name="%(prog)s"
    type="win32"
/>
<description>%(prog)s Program</description>
<dependency>
    <dependentAssembly>
        <assemblyIdentity
            type="win32"
            name="Microsoft.Windows.Common-Controls"
            version="6.0.0.0"
            processorArchitecture="X86"
            publicKeyToken="6595b64144ccf1df"
            language="*"
        />
    </dependentAssembly>
</dependency>
</assembly>
'''

RT_MANIFEST = 24

def opj(path):
    """Convert paths to the platform-specific separator"""
    st = apply(os.path.join, tuple(path.split('/')))
    # HACK: on Linux, a leading / gets lost...
    if path.startswith('/'):
        st = '/' + st
    return st

class Main_File_Target:
    def __init__( self, **kw ):
        self.__dict__.update( kw )
        # for the versioninfo resources
        self.version = "0.1.%d" % counter
        self.company_name = "SNote Technology ltd,. co."
        self.copyright = "Copyright by fla.sam at SNote Technology ltd,. co. 2008"
        self.name = "SNote Main"

#SNote Main File info        
snote_wx = Main_File_Target( 
    # used for the versioninfo resource
    description = "SNote Main File", 

    # what to build
    script = "SNote.pyw", 
    other_resources = [( RT_MANIFEST, 1, manifest_template % dict( prog="Snote" ) )], 
    icon_resources = [( 1, opj("resources/snote.ico") )], 
    dest_base = "" )

# Build SNote Main File
setup( 
    options={"py2exe":{"dist_dir" : "SnoteDist", \
                        "optimize" : 2, \
                        "compressed" : 1, \
                        "ascii" : 0}, 
                    }, 
    windows = [snote_wx], 
    zipfile = 'sn_modules.dll', 

)

#===============================================================================
# class Luncher_File_Target:
#    def __init__( self, **kw ):
#        self.__dict__.update( kw )
#        # for the versioninfo resources
#        self.version = "0.1.%d" % counter
#        self.company_name = "SNote Technology ltd,. co."
#        self.copyright = "Copyright by fla.sam at SNote Technology ltd,. co. 2008"
#        self.name = "SNote Luncher"
#        
# #SNote Main File info        
# snote_luncher_wx = Luncher_File_Target( 
#    # used for the versioninfo resource
#    description = "SNote Luncher File", 
# 
#    # what to build
#    script = "Luncher.pyw", 
#    other_resources = [( RT_MANIFEST, 1, manifest_template % dict( prog="Luncher" ) )], 
#    icon_resources = [( 1, opj("resources/snote.ico") )], 
#    dest_base = "" )
# 
# # Build SNote LuncherFile
# setup( 
#    options={"py2exe":{"dist_dir" : "SnoteDist", \
#                        "optimize" : 2, \
#                        "compressed" : 1, \
#                        "ascii" : 0}, 
#                    }, 
#    windows = [snote_luncher_wx], 
#    zipfile = 'sn_luncher_modules.dll', 
# 
# )
#===============================================================================